<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Logger{
    private $filename; //文件名
    private $file; //文件流
    
    function __construct($filename) {
        $this->filename = $filename;
        $this->file = fopen($filename, "a");
    }
    
    function __destruct() {
        if($this->file){
            fclose($this->file);
        }
    }
    
    function debug($info){
        $this->log("DEBUG", $info);
    }
    
    function info($info){
        $this->log("INFO", $info);
    }
    
    function error($info){
        $this->log("ERROR", $info);
    }
    
    function warning($info){
        $this->log("WARNING", $info);
    }
    
    private function log($type,$info){
        $str =  "[".date("Y-m-d H:i:s",time())."]"."[".$type."] :\t".$info."\r\n";
        fwrite($this->file,$str);
    }
    
}
